<?php
namespace App\Validation;

class AdmintorRules
{

    /**
     * 验证后台登录密码
     * 
     * @param string $str            
     * @param string $fields            
     * @param array $data            
     * @return boolean
     */
    public function valid_admintor(string $str, string $fields, array $data)
    {
        $model = model('admintor');
        $admintor = $model->where('username', $data['username'])->first();
        if (! $admintor)
            return false;
        
        return password_verify(sha1(md5($data['password'])), $admintor['password_hash']);
    }

    /**
     * 验证后台用户登录的状态
     */
    public function valid_admintorStatus(string $str, string $fields, array $data)
    {
        $admintor = model('admintor')->where('username', $data['username'])
            ->where('status', COMMON_STATUS_ON)
            ->first();
        return ! $admintor ? false : true;
    }
}